package com.ict.ms.port.service.api.impl;


import org.springframework.stereotype.Service;

import com.ict.ms.port.facade.api.IPortService;
import com.ict.ms.port.facade.dto.PortDto;
import com.ict.ms.port.facade.model.Port;
import com.ict.ms.port.facade.model.PortInfo;
import com.ict.ms.port.service.dao.IPortDao;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service("portService")
public class PortService  implements  IPortService {
    @Resource
    IPortDao dao;

    /**
     * 港口列表返回
     * @return 返回结果做dto转换。
     */
    public List<PortDto> portList(){
        //model
        List<Port> ports=dao.listPortAll();

        //DTO
        List<PortDto> dtoList=new ArrayList<PortDto>();

        for(Port model:ports){
            PortDto dto=new PortDto();
            dto.setId(model.getId());
            dto.setCc(model.getCc());
            dto.setName(model.getName());
            int lat=(model.getLatitude_degrees()*600000+model.getLatitude_minutes()*10000);
            if(model.getLatitude_hemisphere()!=null){
                if(model.getLatitude_hemisphere().equals("S")){
                    lat=-lat;
                }
            }

            int lon=(model.getLongitude_degrees()*600000+model.getLongitude_minutes()*10000);
            if(model.getLongitude_hemisphere()!=null){
                if(model.getLongitude_hemisphere().equals("W")){
                    lon=-lon;
                }
            }

            dto.setLat(lat);
            dto.setLon(lon);
            dtoList.add(dto);
        }

        return dtoList;
    }

    public PortInfo portInfo(int id){
        PortInfo PortInfo=dao.portInfo(id);
        return PortInfo;
    }

}
